//
// Created by fairy on 2024/9/22.
//
#pragma once

#include <../../HAL/inc/fsmc.hpp>
#include <common_definition.h>
#include <hal.hpp>
#include <stm32f4xx_hal.h>


// GUI
#ifdef ENABLE_GUI
#endif

#ifdef ENABLE_FREERTOS
#include <cmsis_os2.h>
#ifdef ENABLE_FREERTOS_DEBUG
// cpu运行时
#include <cpu_runtime.hpp>
#endif
#endif



namespace core
{

    class baseInit
    {
    public:
        ALWAYS_INLINE static void init()
        {
            using namespace bsp;
            HAL_Init();
            hal::systemClock::defaultConfig();

            // 开启FreeRTOS的运行时统计信息
#if defined(ENABLE_FREERTOS_DEBUG) && defined(ENABLE_FREERTOS)
            ConfigureTimerForRunTimeStats();
#endif

            //按键和lcd都可能用fsmc，这里不做更改
            hal::fsmc::init();

#ifdef ENABLE_DMA_FSMC
            fsmc_dma_init();// 初始化FSMC+DMA
#endif


#ifdef SD_SPI_ENABLE
            spi_sd_init();
#endif

#ifdef ENABLE_FREERTOS
            osKernelInitialize();// FreeRTOS内核初始化
#endif                   // ENABLE_FREERTOS
        }
    };
}// namespace bsp::baseInit




#undef DMA2_S6CR

#ifdef USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
    /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
    for (;;)
    {
    }
}
#endif /* USE_FULL_ASSERT */
